/*
 *      Author: Guannan Ma
 *      @mythmgn
 *      Whatever license applied
 */

/*
 * Note: This queue is not thread-safe. Guannan
 * */

#include "base.h"

#ifndef BASE_LIB_LIBQUEUE_H
#define BASE_LIB_LIBQUEUE_H


#ifdef __cplusplus
extern "C"
{
#endif

    typedef struct queue {
        struct queue *next;
        union {
            void * content;
            int inUseNum;
        };
        struct mlock lock;
    } queue;

    queue * qInit();
    BOOL qClose(queue *pq,BOOL freeContent);
    BOOL isQueueEmpty(queue *pq);
    int qLength(queue *pq);
    void * qPop(queue *pq);
    BOOL qPush(queue *pq,void *content);
    BOOL qEmpty(queue *pq,BOOL freeContent);



/*
 * Enhanced functions
 */


typedef struct niceContent{
	unsigned int nice;
	void *content;
}niceContent;

    /*
     *  content->nice should be accessable. Otherwise, the function will fail with FALSE
     *  Once you use this function instead of qPush, you have to use it all the time until
     *  you don't need to operate on the queue. Otherwise, the correctness of the order cannot
     *  be guaranteed.
     */
    BOOL exQPushWithOrder(queue *q,niceContent *content);


#ifdef __cplusplus
}
#endif

#endif // LIB_QUEUE_H_INCLUDED
